/**
 * This file is used to show error messages from JSON objects via Javascript
 */



function getMessagesHTML(jsonData,path) {
	var content = "";
	dojo.forEach(jsonData.messages,function(message) {
	        var image = "";
	        switch(message.severity) {
	        	case "I": image = "info.png"; break;
	        	case "W": image = "warning.png"; break;
	        	case "E": image = "error.png"; break;
	        }
	        content += "<p><img src=\""+path+"/"+image+"\">"+"&nbsp;&nbsp;"+message.message+"</p>";
	     
	    });
	return content;
}

function showMessages(jsonData,path,autohide) {
	if (typeof path != "string") path = "../images";
	if (typeof autohide != "boolean") autohide = true;

	dojo.forEach(jsonData.messages,function(message) {
        switch(message.severity) {
        	case "I": image = "info.png"; break;
        	case "W": autohide = false; return; break;
        	case "E": autohide = false; return; break;
        }
    });
	
	dojo.byId("messageAreaContent").innerHTML = getMessagesHTML(jsonData,path);
	dojo.fx.wipeIn({ node: dojo.byId("messageArea") }).play();
	if (autohide === true) {
		window.setTimeout("hideMessages()", 10000);
	}
}

function hideMessages() {
	dojo.fx.wipeOut({ node: dojo.byId("messageArea") }).play();
}